package com.zzyy.study.service;

import io.seata.rm.tcc.api.BusinessActionContext;
import io.seata.rm.tcc.api.BusinessActionContextParameter;
import io.seata.rm.tcc.api.LocalTCC;
import io.seata.rm.tcc.api.TwoPhaseBusinessAction;
import org.apache.ibatis.annotations.Param;

/**
 * @auther zzyy
 * @create 2023-12-08 21:33
 */
@LocalTCC
public interface AccountTCCService
{
    /**
     * 扣减库存
     */
    @TwoPhaseBusinessAction(name = "decreaseTcc", commitMethod = "confirm", rollbackMethod = "cancel")
    void decreaseTcc(@BusinessActionContextParameter("userId") Long userId,
                  @BusinessActionContextParameter("money") Long money);

    /**
     *执行TCC事务时，成功就提交事务
     * @param ctx 上下文对象
     * @return 执行结果
     */
    Boolean confirm(BusinessActionContext ctx);

    /**
     * 执行TCC事务时，失败就回滚事务
     * @param ctx 上下文对象
     * @return 执行结果
     */
    Boolean cancel(BusinessActionContext ctx);
}
